package com.lovo.csc.service.impl;

import com.lovo.csc.entity.Vendor;
import com.lovo.csc.service.IVendorService;
import com.lovo.dto.SupplierDto;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;
@Service
public class VendorMQService {
    @Autowired
    IVendorService vendorService;
    //监听供应商注册信息
    @RabbitListener(queues = "REQUESTQUEUE")
    public void order(Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag, SupplierDto dto) throws IOException {
        if(null!=dto) {
            Vendor vendor = new Vendor();
            vendor.setVendorcode(dto.getNumber());
            vendor.setVendoraccount(dto.getCommoduser());
            vendor.setVendorpassword(dto.getPwd());
            vendor.setVendortype(dto.getClasses());
            vendor.setVendorlicense(dto.getImg());
            vendor.setVendorname(dto.getName());
            vendor.setVendoraudit("0");
            vendor.setVendorlevel("1星级用户");
            vendorService.save(vendor);
            channel.basicAck(tag,false);
        }
    }
}
